home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / amiga / plotting / gnuplot3.lzh / gnuplot / eval.c < prev    next >
C/C++ Source or Header  |  1991-07-18  |  4KB  |  150 lines

  1. /* GNUPLOT - eval.c */
  2. /*
  3.  * Copyright (C) 1986, 1987, 1990, 1991   Thomas Williams, Colin Kelley
  4.  *
  5.  * Permission to use, copy, and distribute this software and its
  6.  * documentation for any purpose with or without fee is hereby granted, 
  7.  * provided that the above copyright notice appear in all copies and 
  8.  * that both that copyright notice and this permission notice appear 
  9.  * in supporting documentation.
  10.  *
  11.  * Permission to modify the software is granted, but not the right to
  12.  * distribute the modified code.  Modifications are to be distributed 
  13.  * as patches to released version.
  14.  *  
  15.  * This software is provided "as is" without express or implied warranty.
  16.  * 
  17.  *
  18.  * AUTHORS
  19.  * 
  20.  *   Original Software:
  21.  *     Thomas Williams,  Colin Kelley.
  22.  * 
  23.  *   Gnuplot 2.0 additions:
  24.  *       Russell Lang, Dave Kotz, John Campbell.
  25.  *
  26.  *   Gnuplot 3.0 additions:
  27.  *       Gershon Elber and many others.
  28.  * 
  29.  * Send your comments or suggestions to 
  30.  *  pixar!info-gnuplot@sun.com.
  31.  * This is a mailing list; to join it send a note to 
  32.  *  pixar!info-gnuplot-request@sun.com.  
  33.  * Send bug reports to
  34.  *  pixar!bug-gnuplot@sun.com.
  35.  */
  36.  
  37. #include <stdio.h>
  38. #include "plot.h"
  39.  
  40. extern int c_token;
  41. extern struct ft_entry ft[];
  42. extern struct udvt_entry *first_udv;
  43. extern struct udft_entry *first_udf;
  44. extern struct at_type at;
  45. extern struct lexical_unit token[];
  46.  
  47. struct value *integer();
  48.  
  49.  
  50.  
  51. struct udvt_entry *
  52. add_udv(t_num)  /* find or add value and return pointer */
  53. int t_num;
  54. {
  55. register struct udvt_entry **udv_ptr = &first_udv;
  56.  
  57.     /* check if it's already in the table... */
  58.  
  59.     while (*udv_ptr) {
  60.         if (equals(t_num,(*udv_ptr)->udv_name))
  61.             return(*udv_ptr);
  62.         udv_ptr = &((*udv_ptr)->next_udv);
  63.     }
  64.  
  65.     *udv_ptr = (struct udvt_entry *)
  66.       alloc((unsigned int)sizeof(struct udvt_entry), "value");
  67.     (*udv_ptr)->next_udv = NULL;
  68.     copy_str((*udv_ptr)->udv_name,t_num);
  69.     (*udv_ptr)->udv_value.type = INT;    /* not necessary, but safe! */
  70.     (*udv_ptr)->udv_undef = TRUE;
  71.     return(*udv_ptr);
  72. }
  73.  
  74.  
  75. struct udft_entry *
  76. add_udf(t_num)  /* find or add function and return pointer */
  77. int t_num; /* index to token[] */
  78. {
  79. register struct udft_entry **udf_ptr = &first_udf;
  80.  
  81.     while (*udf_ptr) {
  82.         if (equals(t_num,(*udf_ptr)->udf_name))
  83.             return(*udf_ptr);
  84.         udf_ptr = &((*udf_ptr)->next_udf);
  85.     }
  86.      *udf_ptr = (struct udft_entry *)
  87.       alloc((unsigned int)sizeof(struct udft_entry), "function");
  88.     (*udf_ptr)->next_udf = (struct udft_entry *) NULL;
  89.     (*udf_ptr)->definition = NULL;
  90.     (*udf_ptr)->at = NULL;
  91.     copy_str((*udf_ptr)->udf_name,t_num);
  92.     (void) integer(&((*udf_ptr)->dummy_values[0]), 0);
  93.     (void) integer(&((*udf_ptr)->dummy_values[1]), 0);
  94.     return(*udf_ptr);
  95. }
  96.  
  97.  
  98. union argument *
  99. add_action(sf_index)
  100. enum operators sf_index;        /* index of p-code function */
  101. {
  102.     if (at.a_count >= MAX_AT_LEN)
  103.         int_error("action table overflow",NO_CARET);
  104.     at.actions[at.a_count].index = sf_index;
  105.     return(&(at.actions[at.a_count++].arg));
  106. }
  107.  
  108.  
  109. int standard(t_num)  /* return standard function index or 0 */
  110. {
  111. register int i;
  112.     for (i = (int)SF_START; ft[i].f_name != NULL; i++) {
  113.         if (equals(t_num,ft[i].f_name))
  114.             return(i);
  115.     }
  116.     return(0);
  117. }
  118.  
  119.  
  120.  
  121. execute_at(at_ptr)
  122. struct at_type *at_ptr;
  123. {
  124. register int i,index,count,offset;
  125.  
  126.     count = at_ptr->a_count;
  127.     for (i = 0; i < count;) {
  128.         index = (int)at_ptr->actions[i].index;
  129.         offset = (*ft[index].func)(&(at_ptr->actions[i].arg));
  130.         if (is_jump(index))
  131.             i += offset;
  132.         else
  133.             i++;
  134.     }
  135. }
  136.  
  137. /*
  138.  
  139.  'ft' is a table containing C functions within this program. 
  140.  
  141.  An 'action_table' contains pointers to these functions and arguments to be
  142.  passed to them. 
  143.  
  144.  at_ptr is a pointer to the action table which must be executed (evaluated)
  145.  
  146.  so the iterated line exectues the function indexed by the at_ptr and 
  147.  passes the address of the argument which is pointed to by the arg_ptr 
  148.  
  149. */
  150.